﻿namespace ApiTemplate.WebApi
{
    /// <summary>
    /// 缓存配置
    /// </summary>
    public static class CacheSetup
    {
        /// <summary>
        /// 缓存配置
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="appSetting"></param>
        public static void RegisterCache(this ContainerBuilder builder, AppSetting appSetting)
        {
            if (appSetting.CanUseRedis())
            {
                //使用Redis缓存
                builder.RegisterInstance<ICacheHelper>(new StackExchangeRedisHelper()).PropertiesAutowired();
            }
            else
            {
                //使用MemoryCache
                builder.RegisterInstance<ICacheHelper>(new MemoryCacheHelper()).PropertiesAutowired();
            }
        }
    }
}
